#!/usr/bin/env python
# encoding: utf-8
'''
@author: zhaowenpeng
@contact: winston@peipeiyun.com
@software: garner
@file: site_map.py
@time: 2020/12/3 下午4:52
@desc:
'''


# @cache(MC_KEY_SITEMAP)
# async def _sitemap(request):
#     ten_days_ago = (datetime.now() - timedelta(days=10)).date().isoformat()
#     posts = await Post.get_all()
#     tags = await Tag.filter().order_by('-id')
#     items: List[List] = []
#
#     for rv in [posts, tags]:
#         items.extend([[item.canonical_url, item.created_at] for item in rv])
#
#     for _, route in app.router.routes_names.values():
#         if any(endpoint in route.uri for endpoint in ('/admin', '/j', '/api')):
#             continue
#         if 'GET' in route.methods and not route.parameters:
#             items.append([route.uri, ten_days_ago])
#
#     return await render_string('sitemap.xml', request, {'items': items})

from sanic.response import json
from . import app
@app.route('sitemap.xml')
async def sitemap(request):
    urls=[]
    for rout in request.app.router.routes_all:
        urls.append(rout)
    return json(urls)

